<template>
  <view class="floating-menu">
    <!-- 菜单按钮 -->
    <view class="menu-button" :class="{ 'active': isOpen }" @tap="toggleMenu">
      <image class="menu-icon" src="https://img.icons8.com/material-outlined/96/ffffff/menu.png" />
    </view>
    
    <!-- S形背景 -->
    <view class="menu-background" :class="{ 'open': isOpen }" @tap="handleClose">
      <!-- 菜单项容器 -->
      <view class="menu-items" :class="{ 'open': isOpen }">
        <view 
          class="menu-item" 
          v-for="(item, index) in menuItems" 
          :key="index" 
          @tap.stop="handleItemClick(item)"
        >
          <image class="item-icon" :src="item.icon" />
             
          <text class="item-label">{{ item.label }}</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'FloatingMenu',
  data() {
    return {
      isOpen: false,
      menuItems: [
        {
          icon: 'https://img.icons8.com/material-outlined/96/ffffff/time-machine.png',
          label: '聊天记录', 
          action: 'history'
        },
        {
          icon: 'https://img.icons8.com/material-outlined/96/ffffff/user.png',
          label: '个人中心',
          action: 'profile'
        },
        {
          icon: 'https://img.icons8.com/material-outlined/96/ffffff/settings.png',
          label: '设置',
          action: 'settings'
        }
      ]
    }
  },
  methods: {
    toggleMenu() {
      this.isOpen = !this.isOpen
    },
    handleClose() {
      this.isOpen = false
    },
    handleItemClick(item) {
      this.$emit('menuAction', item.action)
      this.isOpen = false
    }
  }
}
</script>

<style lang="scss" scoped>
.floating-menu {
  position: fixed;
  left: 16px;
  bottom: 100px;
  z-index: 999;
}

.menu-button {
  width: 44px;
  height: 44px;
  background: #007AFF;
  border-radius: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
  position: relative;
  z-index: 1001;
  
  .menu-icon {
    width: 24px;
    height: 24px;
  }
}

.menu-background {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1000;
  
  &::before {
    content: '';
    position: absolute;
    left: 0;
    bottom: 80px;
    width: 60%;
    height: 100%;
    background: rgba(0, 122, 255, 0.95);
    clip-path: path('M0 100vh C 0 70vh 40% 50vh 60% 0vh V 100vh Z');
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }
  
  &.open {
    pointer-events: auto;
    
    &::before {
      transform: translateX(0);
    }
  }
}

.menu-items {
  position: absolute;
  left: 30px;
  bottom: 160px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  opacity: 0;
  transform: translateX(-20px);
  transition: all 0.3s ease;
  
  &.open {
    opacity: 1;
    transform: translateX(0);
  }
}

.menu-item {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 25px;
  backdrop-filter: blur(10px);
  transition: transform 0.3s ease;
  
  &:hover {
    transform: translateX(5px);
    background: rgba(255, 255, 255, 0.2);
  }
  
  .item-icon {
    width: 24px;
    height: 24px;
    margin-right: 12px;
  }
  
  .item-label {
    font-size: 16px;
    color: #fff;
    font-weight: 500;
  }
}
</style> 